//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.ctrip.corp.obt.shard.constants;

import com.ctrip.corp.obt.generic.utils.StringUtils;
import com.ctrip.corp.obt.shard.loader.CPShardSourceLoader;
import com.ctrip.corp.obt.shard.loader.FullShardSourceLoader;
import com.ctrip.corp.obt.shard.loader.IShardSourceLoader;
import com.ctrip.corp.obt.shard.loader.SingleShardSourceLoader;

public enum SourceLoadMode {

    /**
     * 全量加载
     */
    FULL(1, "full", FullShardSourceLoader.class),

    /**
     * 控制面加载
     */
    CONTROL_PLANE(2, "controlPlane", CPShardSourceLoader.class),

    /**
     * 只加载默认数据源并屏蔽数据源load接口
     */
    SINGLE(3, "single", SingleShardSourceLoader.class);

    private Integer value;

    private String name;

    private Class<? extends IShardSourceLoader> classType;

    SourceLoadMode(Integer value, String name, Class<? extends IShardSourceLoader> classType) {
        this.value = value;
        this.name = name;
        this.classType = classType;
    }

    public Integer getValue() {
        return value;
    }


    public String getName() {
        return name;
    }

    public Class<? extends IShardSourceLoader> getClassType() {
        return classType;
    }

    /**
     * 根据sourceLoaderName获取class
     * @param sourceLoaderName {@link com.ctrip.corp.obt.shard.loader.IShardSourceLoader}
     * @return
     */
    public static Class<? extends IShardSourceLoader> getLoaderClassType(String sourceLoaderName) {
        if (StringUtils.isBlank(sourceLoaderName)) {
            return null;
        }
        for (SourceLoadMode sourceLoadMode : values()) {
            if (sourceLoadMode.getName().equals(sourceLoaderName)) {
                return sourceLoadMode.getClassType();
            }
        }
        return null;
    }
}
